package Page.AboutUs;

import Navigation.NavigationController;
import Dao.GraduateDao;
import DataClass.Graduate;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GraduatePage {
    public static Scene getScene() {
        StackPane GraduateMenuPane = new StackPane();
        Label label = new Label("Graduate Menu Page");

        // 创建表格
        TableView<Graduate> tableView =  new TableView<>();

        // 创建列
        TableColumn<Graduate,String> idColumn = new TableColumn<>("学号");
        idColumn.setCellValueFactory(new PropertyValueFactory<Graduate,String>("SNo"));

        TableColumn<Graduate,String> sexColumn = new TableColumn<>("性别");
        sexColumn.setCellValueFactory(new PropertyValueFactory<Graduate,String>("SSex"));

        TableColumn<Graduate,String> typeColumn = new TableColumn<>("类别");
        typeColumn.setCellValueFactory(new PropertyValueFactory<Graduate,String>("SType"));

        TableColumn<Graduate,String> inColumn = new TableColumn<>("入学时间");
        inColumn.setCellValueFactory(new PropertyValueFactory<Graduate,String>("SIn"));

        TableColumn<Graduate,String> outColumn = new TableColumn<>("毕业时间");
        outColumn.setCellValueFactory(new PropertyValueFactory<Graduate,String>("SOut"));

        TableColumn<Graduate,String> teacherAdminPositionsCollegeColumn = new TableColumn<>("初次就业单位");

        // 填充列表
        List<TableColumn<Graduate, ?>> columns = new ArrayList<>();
        columns.add(idColumn);
        columns.add(sexColumn);
        columns.add(typeColumn);
        columns.add(inColumn);
        columns.add(outColumn);
        columns.add(teacherAdminPositionsCollegeColumn);
        tableView.getColumns().addAll(columns);

        // 装入数据
        try {
            List<Graduate> data = GraduateDao.getGraduate();
            tableView.getItems().addAll(data);
        }catch (SQLException ignored)
        {
            System.err.println("数据库出现错误");
        }

        GraduateMenuPane.getChildren().add(label);
        GraduateMenuPane.getChildren().add(tableView);

        VBox vbox = new VBox();
        Button button = new Button("返回");
        button.setOnAction(event -> {
            NavigationController.back();
        });
        vbox.getChildren().add(button);
        vbox.getChildren().add(GraduateMenuPane);
        return new Scene(vbox);
    }
}
